<?

class sms_controller_admin_announcement extends AdminController {
	/**
	 * 
	 *
	 * @var sms_model_announcement
	 */
	var $o;
	public function add_form_action(){
		
	}
	
	public function add_action(){
		$this->o = Model::factory('sms_model_announcement');
		$title = $this->title;
		$content = $this->content;
		if($title and $content){
			$this->o->add(array('title'=>$title, 'content'=>$content));
			$this->_renderRedirect();
		}else{
			throw new Exception('填写信息不完整', 1);
		}
	}
	
	public function edit_form_action(){
		$this->o = Model::factory('sms_model_announcement');
		$this->ret = self::success($this->o->select($this->id));
		$this->view = 'add_form';
	}
	
	public function list_action(){
		$this->o = Model::factory('sms_model_announcement');
		$this->ret = self::success($this->o->selectPage(_('page', 1), 20));
	}
	
	public function delete_action(){
		$this->o = Model::factory('sms_model_announcement');
		$this->o->delete($this->id);
		$this->_renderRedirect();
	}
	
	public function edit_action(){
		$this->o = Model::factory('sms_model_announcement');
		$id = $this->id;
		$title = $this->title;
		$content = $this->content;
		if($id and $title and $content){
			$this->o->update(array('id'=>$id, 'title'=>$title, 'content'=>$content));
			$this->_renderRedirect();
		}else{
			throw new Exception('填写信息不完整', 1);
		}
	}
}